package com.example.demo2.controller;

import com.example.demo2.controller.requests.ModifyDrinkRequest;
import com.example.demo2.model.Drink;
import com.example.demo2.model.Student;
import lombok.extern.slf4j.Slf4j;
import org.joda.money.Money;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {
    LocalDate now =LocalDate.now();
    //get  student
    @GetMapping("/stu/all")
    public List<Student> getAll() {
        //mock数据
        List<Student> result = new ArrayList<>();
        result.add(Student.builder().id(1).name("丁家豪").adminssionDate(now).major("移动应用开发一班").build());
        result.add(Student.builder().id(2).name("张三").adminssionDate(now).major("信息安全与管理一班").build());
        result.add(Student.builder().id(3).name("李四").adminssionDate(now).major("软件一班").build());
        result.add(Student.builder().id(4).name("王五").adminssionDate(now).major("幼教一班").build());return result;
    }

    @GetMapping("/{id}")
    public Student getDrink(@PathVariable Integer id) {
        log.info("学生id：{}", id);
        Student student = Student.builder().id(2).name("家豪").adminssionDate(now).major("移动应用开发一班").build();
        return student;
    }

    //新增
    @PostMapping("/stu/add")
    public Student AddNewStudent(@RequestBody Student student) {
        log.info("创建新学生信息：{}", student);
        Student Addstudent = Student.builder().id(2).name("家豪").adminssionDate(now).major("移动应用开发一班").build();
        return Addstudent;
    }

    //修改学生信息
    @PutMapping("/")
    public Student modIfyStudent(@RequestBody Student student) {
        log.info("要修改的学生：{}", student);
        Student AddStudent = Student.builder().id(2).name("家豪").adminssionDate(now).major("移动应用开发一班").build();
        return AddStudent;
    }

    @DeleteMapping("/stu/del/{id}")
    public String deleteStudent(@PathVariable Integer id) {
        log.info("要删除的学生id:"+id);
        return "删除成功";
    }
}
